****APPENDIX TABLE D7****

cd "$main_dir/output/tables/appendix_d"

global basic 	sex marital religion edu ethnicity birth_state
global extra	employment_status occupation income urban
global time 	survey_year age generation
global polit    party partisan

//--------------------------------------------------------
//Define relevant program
//--------------------------------------------------------

capture program drop standardize_var
program define standardize_var
	
	args var
	
	cap drop z*
	local varlist trust_fed_govt wgrowth_rate_1 `var' yob_ln_gdppc
	foreach var of local varlist {
		egen z`var' = std(`var') if e(sample)==1
}														

end

//--------------------------------------------------------
//Read in relevant data
//--------------------------------------------------------

clear
use "$data_dir/clean/anes_final.dta"

egen scode_survey_year = group(state_code survey_year)

//--------------------------------------------------------
//Create Table D7 (Panel A)
//--------------------------------------------------------

//Column 1
qui reghdfe trust_fed_govt wgrowth_rate_1 sd_inflation yob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
standardize_var sd_inflation
reghdfe ztrust_fed_govt zwgrowth_rate_1 zsd_inflation zyob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
outreg2 using table_d7_panel_a.doc, replace dec(3) nocons addtext(State FE, Yes, ///
														 Survey Year FE, Yes, ///
														 Generation FE, Yes, ///
														 State FE x Survey Year FE, No) keep(zwgrowth_rate_1 zsd_inflation) 												 

//Columns 2-7													 
local varlist wprop_unrest_1 wno_exec_changes_1 wprop_affect_epidemic_1 wbank_crisis_1 wcurrency_crisis_1 wtwin_crisis_1
foreach var of local varlist {
	qui reghdfe trust_fed_govt wgrowth_rate_1 `var' yob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
	standardize_var `var'
	reghdfe ztrust_fed_govt zwgrowth_rate_1 z`var' zyob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
	outreg2 using table_d7_panel_a.doc, append dec(3) nocons addtext(State FE, Yes, ///
														   Survey Year FE, Yes, ///
														   Generation FE, Yes, ///
														   State FE x Survey Year FE, No) keep(zwgrowth_rate_1 z`var') 													
}

//--------------------------------------------------------
//Create Table D7 (Panel B)
//--------------------------------------------------------

//Column 1
qui reghdfe trust_fed_govt wgrowth_rate_1 sd_inflation yob_ln_gdppc, absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
standardize_var sd_inflation
reghdfe ztrust_fed_govt zwgrowth_rate_1 zsd_inflation zyob_ln_gdppc, absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
outreg2 using table_d7_panel_b.doc, replace dec(3) nocons addtext(State FE, No, ///
														Survey Year FE, No, ///
														Generation FE, Yes, ///
														State FE x Survey Year FE, Yes) keep(zwgrowth_rate_1 zsd_inflation) 	

//Columns 2-7														
local varlist wprop_unrest_1 wno_exec_changes_1 wprop_affect_epidemic_1 wbank_crisis_1 wcurrency_crisis_1 wtwin_crisis_1
foreach var of local varlist {	
	qui reghdfe trust_fed_govt wgrowth_rate_1 `var' yob_ln_gdppc, absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
	standardize_var `var'
	reghdfe ztrust_fed_govt zwgrowth_rate_1 z`var' zyob_ln_gdppc, absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
	outreg2 using table_d7_panel_b.doc, append dec(3) nocons addtext(State FE, No, ///
														   Survey Year FE, No, ///
														   Generation FE, Yes, ///
														   State FE x Survey Year FE, Yes) keep(zwgrowth_rate_1 z`var') 													
}
